import qreust from '@/utils/requst'
//  获取频道
export const getchanneApi = () =>
  qreust({
    url: '/v1_0/user/channels'
  })
//获取文章新闻推荐
export const getArticlesApi = (channel_id, timestamp) =>
  qreust({
    url: '/v1_0/articles',
    params: {
      channel_id,
      timestamp
    }
  })
/**
 *
 * @returns  获取频道
 */
export const getAllchanneApi = () =>
  qreust({
    url: '/v1_0/channels'
  })
/**
 * 删除我的频道
 * @param {id} 传过去的id
 * @returns
 */
export const delMychanneApi = (target) =>
  qreust({
    url: `/v1_0/user/channels/${target}`,
    method: 'DELETE'
  })
/**
 * 添加我的频道
 * @param {Number} 频道的id
 * @param {Number} 存进去的位置索引
 * @returns
 */
export const addMyChanneApi = (id, seq) =>
  qreust({
    url: '/v1_0/user/channels',
    method: 'PATCH',
    data: {
      channels: [
        {
          id,
          seq
        }
      ]
    }
  })
/**
 * 自动联想
 * @param {String} 字符串
 * @returns  Promise
 */
export const seatchApi = (q) =>
  qreust({
    url: '/v1_0/suggestion',
    params: {
      q
    }
  })
/**
 * 获取搜索结果
 * @param {String}  搜索页码默认为1
 * @param {number} 每页的数量
 * @param {number} 关键词
 * @returns
 */
export const searchApi = (page, q, per_page) =>
  qreust({
    url: '/v1_0/search',
    params: {
      page,
      q,
      per_page
    }
  })
